package web.exercise.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class TestEncode	extends HttpServlet {
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		resp.setContentType("text/html; charset=utf-8");
		String value=req.getParameter("value");
		byte[] buf=value.getBytes("ISO-8859-1");
		String name=new String(buf,"gbk");
		
		System.out.println(name);
		resp.getWriter().write(name);
	}
	
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		// TODO Auto-generated method stub
		req.setCharacterEncoding("gbk");
		resp.setContentType("text/html; charset=gbk");
		String value=req.getParameter("value");
		byte[] buf=value.getBytes("ISO-8859-1");
		String name=new String(buf,"gbk");
		System.out.println(value);
		System.out.println(name);
		resp.getWriter().write(name);
	}
}
